export const utils = {
  //格式化字符串
  formatName: (str: string, num: number = 4): string => {
    return str ? str.substring(0, num) + "..." + str.substring(str.length - num, str.length) : "";
  },
  playAudio: (src: string, loop: boolean = false): void => {
    let audio: HTMLAudioElement | null = new Audio(src);
    // 设置是否循环播放  
    audio.loop = loop;

    audio.play()
      .then(() => {
        console.log('音频播放成功', src);
      })
      .catch((error) => {
        console.error('音频播放失败:', error);
      });

    audio.addEventListener('ended', () => {
      audio = null
    })
  }
}